<!--
 * @Author: your name
 * @Date: 2019-11-01 18:14:41
 * @LastEditTime: 2019-11-03 19:57:34
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \1101作业\likou.html
 -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>

</body>
<script>
    var isMatch = function(s, p) {
        if (s.length === 0 && p.length === 0) {
            return true;
        }
        if (s.length !== 0 && p.length === 0) {
            return false;
        }

        const char = s[0];
        const pattern = p[0];
        if (!(p[1] === '*')) {
            if (char && (char === pattern || pattern === '.')) {
                return isMatch(s.slice(1), p.slice(1));
            } else {
                return false;
            }
        } else {
            if (char && (char === pattern || pattern === '.')) {
                return isMatch(s.slice(1), p.slice(2)) || isMatch(s.slice(1), p) || isMatch(s, p.slice(2))
            } else {
                return isMatch(s, p.slice(2));
            }
        }
    };





    var letterCombinations = function(digits) {
        let obj = {
            "0": [],
            "1": [],
            "2": ["a", "b", "c"],
            "3": ["d", "e", "f"],
            "4": ["g", "h", "i"],
            "5": ["j", "k", "l"],
            "6": ["m", "n", "o"],
            "7": ["p", "q", "r", "s"],
            "8": ["t", "u", "v"],
            "9": ["w", "x", "y", "z"]
        }

        let arr = [];
        if (digits.length == 0) {
            return arr;
        } else if (digits.length == 1) {
            return obj[digits];
        } else {
            for (let key of digits) {
                arr.push(obj[key]);
            }

            let res = arr.reduce(function(prev, cur) {
                let tempArr = [];
                prev.forEach(prevItem => {
                    cur.forEach(curItem => {
                        tempArr.push(prevItem + curItem);
                    });
                });
                return tempArr;
            });
            return res;

        }


    };
    console.log(letterCombinations("234"))
</script>

</html>